// 默认参数是一个空对象
// 结构 消息提示框
const toast = ({ title = '数据加载中...', icon = 'none', duration = 2000, mask = true } = {}) => {
    // 显示加载
    wx.showToast({
        title,
        icon,
        duration,
        mask
    })
}
// 确认框
const modal = (options = {}) => {
    return new Promise(resolve => {
        const defaultObj = {
            title: '提示',
            content: '您确定执行该操作吗?',
            confirmColor: '#f3514f'
        }
        // 通过浅拷贝覆盖
        const opts = Object.assign({}, defaultObj, options)
        wx.showModal({
          ...opts,
          complete: (res) => {
            if (res.cancel) {
              resolve(false)
            }
            if (res.confirm) {
                resolve(true)
            }
          }
        })
    })
}
// wx 全局挂载
wx.toast = toast
wx.modal = modal
// 导出toast
export {toast,modal}